﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using ActiveStory.IO.XmlElementNames;

namespace ActiveStory.IO
{
    public class XmlActiveStoryProjectWriter : IActiveStoryProjectWriter
    {
        #region IActiveStoryProjectWriter Members

        public void SaveFile(string filename, string projectName, int pageCounter, string pageLookupTableLocation, System.Windows.Point defaultCanvasSize, System.Windows.Media.Color defaultCanvasColor)
        {
            XmlWriterSettings xws = new XmlWriterSettings();
            xws.Indent = true;
            xws.CloseOutput = true;
            XmlWriter xw = XmlWriter.Create(filename, xws);
            xw.WriteStartDocument();
            xw.WriteStartElement(ProjectFileXmlNames.RootElement);

            xw.WriteStartElement(ProjectFileXmlNames.ProjectNameElement);
            xw.WriteValue(projectName);
            xw.WriteEndElement();

            xw.WriteStartElement(ProjectFileXmlNames.PageCounterElement);
            xw.WriteValue(pageCounter);
            xw.WriteEndElement();

            xw.WriteStartElement(ProjectFileXmlNames.PageLookupFileLocElement);
            xw.WriteValue(pageLookupTableLocation);
            xw.WriteEndElement();

            xw.WriteStartElement(ProjectFileXmlNames.DefaultCanvasWidthElement);
            xw.WriteValue(defaultCanvasSize.X);
            xw.WriteEndElement();

            xw.WriteStartElement(ProjectFileXmlNames.DefaultCanvasHeightElement);
            xw.WriteValue(defaultCanvasSize.Y);
            xw.WriteEndElement();

            xw.WriteStartElement(ProjectFileXmlNames.DefaultCanvasColorElement);
            xw.WriteValue(defaultCanvasColor.ToString());
            xw.WriteEndElement();

            xw.WriteEndElement();   //End Root Element
            xw.WriteEndDocument();
            xw.Flush();
            xw.Close();
        }

        #endregion
    }
}
